package org.example.checkStore.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.example.warehouse.domain.WarehouseStore;
import org.example.warehouse.service.IWarehouseStoreService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import org.example.checkStore.domain.CheckWarehouseStore;
import org.example.checkStore.service.ICheckWarehouseStoreService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 盘点仓库Controller
 *
 * @author 小孟微信：xiaomengcode
 * @date 2024-04-26
 */
@Controller
@RequestMapping("/checkStore/checkStore")
public class CheckWarehouseStoreController extends BaseController
{
    private String prefix = "checkStore/checkStore";

    @Autowired
    private ICheckWarehouseStoreService checkWarehouseStoreService;

    @Autowired
    private IWarehouseStoreService warehouseStoreService;

    @GetMapping()
    public String checkStore()
    {
        return prefix + "/checkStore";
    }

    /**
     * 查询盘点仓库列表
     */
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(CheckWarehouseStore checkWarehouseStore)
    {
        startPage();
        List<CheckWarehouseStore> list = checkWarehouseStoreService.selectCheckWarehouseStoreList(checkWarehouseStore);
        return getDataTable(list);
    }

    /**
     * 导出盘点仓库列表
     */
    @RequiresPermissions("checkStore:checkStore:export")
    @Log(title = "盘点仓库", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(CheckWarehouseStore checkWarehouseStore)
    {
        List<CheckWarehouseStore> list = checkWarehouseStoreService.selectCheckWarehouseStoreList(checkWarehouseStore);
        ExcelUtil<CheckWarehouseStore> util = new ExcelUtil<CheckWarehouseStore>(CheckWarehouseStore.class);
        return util.exportExcel(list, "盘点仓库数据");
    }

    /**
     * 新增盘点仓库
     */
    @GetMapping("/add")
    public String add(WarehouseStore warehouseStore ,ModelMap mmp)
    {
        List<WarehouseStore> list = warehouseStoreService.selectWarehouseStoreList(warehouseStore);
        mmp.put("list",list);
        return prefix + "/add";
    }

    /**
     * 新增保存盘点仓库
     */
    @RequiresPermissions("checkStore:checkStore:add")
    @Log(title = "盘点仓库", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(CheckWarehouseStore checkWarehouseStore)
    {
        return toAjax(checkWarehouseStoreService.insertCheckWarehouseStore(checkWarehouseStore));
    }

    /**
     * 修改盘点仓库
     */
    @RequiresPermissions("checkStore:checkStore:edit")
    @GetMapping("/edit/{checkWarehouseStoreId}")
    public String edit(@PathVariable("checkWarehouseStoreId") Long checkWarehouseStoreId, ModelMap mmap)
    {
        CheckWarehouseStore checkWarehouseStore = checkWarehouseStoreService.selectCheckWarehouseStoreByCheckWarehouseStoreId(checkWarehouseStoreId);
        mmap.put("checkWarehouseStore", checkWarehouseStore);
        return prefix + "/edit";
    }

    /**
     * 修改保存盘点仓库
     */
    @RequiresPermissions("checkStore:checkStore:edit")
    @Log(title = "盘点仓库", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(CheckWarehouseStore checkWarehouseStore)
    {
        return toAjax(checkWarehouseStoreService.updateCheckWarehouseStore(checkWarehouseStore));
    }

    /**
     * 删除盘点仓库
     */
    @RequiresPermissions("checkStore:checkStore:remove")
    @Log(title = "盘点仓库", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(checkWarehouseStoreService.deleteCheckWarehouseStoreByCheckWarehouseStoreIds(ids));
    }
}
